package com.www.applyword.ui.my;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.allen.library.SuperButton;
import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.bean.LoginBean;
import com.www.applyword.bean.ResumeBean;
import com.www.applyword.event.EventConstants;
import com.www.applyword.event.MessageEvent;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;
import com.www.applyword.utils.SPUtil;
import com.www.applyword.utils.Utils;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;

/**
 * author : huang
 * date   : 2019/10/24 0024 18:00
 * version: 1.0
 */
public class SkillsActivity extends BaseActivity {
    @BindView(R.id.et)
    EditText et;
    @BindView(R.id.et_school)
    EditText et_school;
    @BindView(R.id.sb_delete)
    SuperButton sbDelete;
    private ResumeBean.ResumeCertificateBean skillBean;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.skills_activity);
        setTitle("技能/证书");
        setRringTitle("保存");
        tv_right.setOnClickListener(v -> {
            saveResumeEvaluate();
        });
    }

    private void saveResumeEvaluate() {
        if (TextUtils.isEmpty(et_school.getText().toString().trim())) {
            Utils.showToastSafe("请填写技能名称");
            return;
        }
        if (TextUtils.isEmpty(et.getText().toString().trim())) {
            Utils.showToastSafe("请填写相关介绍");
            return;
        }
        Map<String, Object> params = new HashMap<>();
        params.put("ResumeCertificate_UserID", SPUtil.getString(Constants.USERID));
        params.put("ResumeCertificate_ID", "");
        params.put("ResumeCertificate_Name", et_school.getText().toString().trim());
        params.put("ResumeCertificate_Introduce", et.getText().toString().trim());
        params.put("ResumeCertificate_Imgs", "");
        HttpClient.post(SkillsActivity.this, Constants.RESUMECERTIFICATE, params, new CallBack<LoginBean>() {
            @Override
            public void onSuccess(LoginBean result) {
                Utils.showToastSafe("保存成功");
                MessageEvent messageEvent = new MessageEvent();
                messageEvent.setMessageKey(EventConstants.DEL_RESUMESCHOOL);
                EventBus.getDefault().post(messageEvent);
                finish();
            }
        });
    }

    @Override
    protected void loadData() {
        skillBean = (ResumeBean.ResumeCertificateBean) getIntent().getSerializableExtra("skillBean");
        if (null != skillBean) {
            et_school.setText(skillBean.getResumeCertificate_Name());
            et.setText(skillBean.getResumeCertificate_Introduce());
            sbDelete.setVisibility(View.VISIBLE);
            sbDelete.setOnClickListener(v -> {
                Map<String, Object> params = new HashMap<>();
                params.put("ResumeCertificateID",skillBean.getResumeCertificate_ID());
                HttpClient.get(SkillsActivity.this, Constants.DELRESUMECERTIFICATE, params,new CallBack<LoginBean>() {
                    @Override
                    public void onSuccess(LoginBean result) {
                        Utils.showToastSafe("删除成功");
                        MessageEvent messageEvent = new MessageEvent();
                        messageEvent.setMessageKey(EventConstants.DEL_RESUMESCHOOL);
                        EventBus.getDefault().post(messageEvent);
                        finish();
                    }
                });
            });
        }
    }


}
